<template>
  <el-table :data="tableData" stripe>
    <el-table-column prop="id" label="id" width="140">
    </el-table-column>
    <el-table-column prop="name" label="姓名" width="120">
    </el-table-column>
    <el-table-column prop="score" label="score">
    </el-table-column>

    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini" type="success" icon="el-icon-edit"
          @click="editUser(scope.$index, scope.row)"></el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

</template>

<script>
import instance from "../utils/request";

export default {
  name: "usertable",
  data() {
    return {
      tableData: []
    }
    /*const item = {
      id:
      date: '2016-05-02',
      name: '王小虎',
      address: '上海市普陀区金沙江路 1518 弄'
    };
    return {
      tableData: Array(5).fill(item)
    }*/
  },
  methods: {
    editUser(index, row) {
      //console.log(index, row);
      instance.get("/stu/modifyQuery?id="+row.id)
        .then(res=>{
          console.log(res.data);
        })
    },
    handleDelete(index, row) {
      instance.get("/stu/remove?id="+row.id)
        .then(res=>{
          this.$message({
            message: '恭喜你，删除成功！',
            type: 'success'
          });
        })
    }
  },
  created() {
    instance.get("/stu/queryAll")
      .then(res=>this.tableData=res.data)
  }
}
</script>

<style scoped>

</style>
